package com.get;

import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import com.add.Job1;
import com.jdbcUtil.*;

public class Job1Impl {
	public ArrayList<Job1> getBiList(int postid) {
		ArrayList<Job1> ciList=new ArrayList<Job1>();
		Connection Conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			Conn = JDBCUtil.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		// 创建一个可以滚动的只读的SQL语句对象
		try {
			stmt = Conn.createStatement(
					java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
					java.sql.ResultSet.CONCUR_READ_ONLY);
		} catch (SQLException e) {
			e.printStackTrace();
		}// // 准备SQL语句
		String sql="SELECT *  FROM jobtype1 where postid="+postid+";";
		// 执行SQL语句并获取结果集
		try {
			rs = stmt.executeQuery(sql);
			while(rs.next()){//1
				Job1 j1=new Job1();
				j1.setId(rs.getInt("jobid"));//set get
				j1.setJobName(rs.getString("jobname"));
				j1.setJobType(rs.getString("jobtype"));
				j1.setNotcie(rs.getString("notice"));
				j1.setPayType(rs.getString("paytype"));
				j1.setPlace(rs.getString("place"));
				j1.setPostId(rs.getInt("postid"));
				j1.setSalary(rs.getInt("salary"));
				j1.setState(rs.getInt("jobstate"));
				j1.setWorkTime(rs.getString("date"));
				ciList.add(j1);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return ciList;
	}

	////按照工作id查询
	public Job1 getJob1(int Jobid){
		Job1 j1=new Job1();
		Connection conn=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		try{
			conn=JDBCUtil.getConnection();
			String sql="select * from jobtype1 where jobid="+Jobid+";";
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			if(rs.next()){
				j1.setId(rs.getInt("jobid"));
				j1.setJobName(rs.getString("jobname"));
				j1.setJobType(rs.getString("paytype"));
				j1.setNotcie(rs.getString("notice"));
				j1.setPayType(rs.getString("paytype"));
				j1.setPlace(rs.getString("place"));
				j1.setPostId(rs.getInt("postid"));
				j1.setSalary(rs.getInt("salary"));
				j1.setState(rs.getInt("jobstate"));
				j1.setWorkTime(rs.getString("date"));
				return j1;
			}
		}catch(Exception e){
			System.out.println(e);
		}finally{
			JDBCUtil.free(conn, ps, rs);
		}
		return null;
	}
}
